package lc.动态规划;

/**
 * @description: 买卖股票的最佳时机
 * @author: qian
 * @createDate: 2021/9/12
 */
public class Math121 {

    public int maxProfit(int[] prices) {

        if (prices.length == 0)
            return 0;
        int res = 0;
        int min = prices[0];
        for(int i = 1; i < prices.length; i++) {
            res = Math.max(res,prices[i] - min);
            min = Math.min(min,prices[i]);
        }
        return res;
    }

}
